package com.bsdk.install.device.comm;

import com.alibaba.fastjson2.JSONObject;
import com.bsdk.common.core.domain.AjaxResult;
import com.bsdk.install.device.DeviceBase;
import com.bsdk.install.device.constants.LockConstants;
import com.bsdk.install.device.lockLora.v1.cmd.ANALYSIS;
import com.bsdk.install.device.lockLora.v1.cmd.COMMAND;

/**
 * @author sunjian0225@163.com
 * @version 1.0
 * @title CommDevice
 * @description
 * @create 2024/2/2 11:21
 */

public class CommDevice extends DeviceBase {

    private JSONObject deviceCommand = new JSONObject();

    public CommDevice(String devId, String cMac,String fMac) {
        super();
        this.setcMac(cMac);
        this.setDevId(devId);
        this.setFmac(fMac);
        this.deviceCommand.put("devId", this.getDevId());
        this.deviceCommand.put("cMac", this.getcMac());
        this.deviceCommand.put("fMac",this.getFmac());
        //生成不同的UID 只能是自增
        this.deviceCommand.put("uId", String.valueOf(LockConstants.COUNTER.getAndIncrement()));


    }

    public CommDevice() {
        super();
    }



    public AjaxResult commandPing() {
        this.deviceCommand.put("cMac", "8000"+this.getcMac().substring(4));
        this.deviceCommand.put("cmd", "00010A");
        COMMAND cmd = new COMMAND();
        this.deviceCommand.put("data", cmd.pinglock());
        return AjaxResult.success(this.deviceCommand);

    }

    public AjaxResult commandBind()
    {
        this.deviceCommand.put("cMac", "8000"+this.getcMac().substring(4));
        this.deviceCommand.put("cmd", "00010A");
        COMMAND cmd = new COMMAND();
        //this.deviceCommand.put("data", cmd.registlock());
        this.deviceCommand.put("data",cmd.registlock(this.getcMac().substring(4)));
        return AjaxResult.success(this.deviceCommand);
    }

    public AjaxResult commandBind(String gwMac)
    {
        this.deviceCommand.put("cMac", "8000"+this.getcMac().substring(4));
        this.deviceCommand.put("cmd", "00010A");
        COMMAND cmd = new COMMAND();
        //this.deviceCommand.put("data", "0207007E0050C262C21E8DFF");
        this.deviceCommand.put("data",cmd.registlock(gwMac));
        return AjaxResult.success(this.deviceCommand);
    }

    public AjaxResult commandSearch()
    {
        this.deviceCommand.put("cMac", "8000"+this.getcMac().substring(4));
        this.deviceCommand.put("cmd", "00010A");
        COMMAND cmd = new COMMAND();

        this.deviceCommand.put("data",cmd.req_registlock());
        return AjaxResult.success(this.deviceCommand);
    }
    public AjaxResult commandReset()
    {
        this.deviceCommand.put("cMac", "8000"+this.getcMac().substring(4));
        this.deviceCommand.put("cmd", "00014A");
        COMMAND cmd = new COMMAND();
        this.deviceCommand.put("data", cmd.reset());
        return AjaxResult.success(this.deviceCommand);
    }

    public JSONObject result(JSONObject jsonObject){

        return (new ANALYSIS()).dealJsonData(jsonObject);
    }

}
